﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>上传头像</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            margin: 20px;
            background: #f0f2f5;
        }

        .top-bar {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
            padding: 0 20px;
        }

        .user-info {
            font-size: 18px;
            margin-right: 30px;
            color: #333;
        }

        .main-layout {
            display: flex;
            max-width: 1000px;
            margin: 30px auto 0 auto;
            min-height: 600px;
        }

        .sidebar {
            width: 220px;
            background: white;
            border-radius: 8px;
            padding: 15px 0;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            margin-right: 24px;
            flex-shrink: 0;
        }

        .menu-item {
            padding: 12px 20px;
            cursor: pointer;
            transition: all 0.3s;
            color: #666;
        }

            .menu-item:hover {
                background: #f5f5f5;
                color: #333;
            }

            .menu-item.active {
                color: #1890ff;
                background: #e6f7ff;
                border-right: 3px solid #1890ff;
            }

        .content {
            flex: 1;
            background: white;
            padding: 25px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            min-width: 0;
        }

        .upload-section {
            text-align: center;
            max-width: 500px;
            margin: 0 auto;
        }

        .upload-option {
            display: flex;
            flex-direction: column;
            gap: 20px;
            margin-top: 30px;
        }

        .upload-btn {
            padding: 12px 24px;
            border: 1px solid #1890ff;
            border-radius: 4px;
            background: #e6f7ff;
            color: #1890ff;
            cursor: pointer;
            transition: all 0.3s;
        }

            .upload-btn:hover {
                background: #1890ff;
                color: white;
            }
    </style>
</head>
<body>
    <div class="top-bar">
        <div class="user-info">
            <span class="username">@ViewBag.UserName</span>
        </div>
    </div>

    <div class="main-layout">
        <div class="sidebar">
            <div class="menu-item @(ViewBag.ActiveMenu == "Person" ? "active" : "")" onclick="location.href='@Url.Action("Person", "Home")'">基本信息</div>
            <div class="menu-item @(ViewBag.ActiveMenu == "Uploadface" ? "active" : "")" onclick="location.href='@Url.Action("Uploadface", "Home")'">上传头像</div>
            <div class="menu-item @(ViewBag.ActiveMenu == "Blog" ? "active" : "")" onclick="location.href='@Url.Action("Blog", "Home")'">我的博客</div>
            <div class="menu-item @(ViewBag.ActiveMenu == "ModifyData" ? "active" : "")" onclick="location.href='@Url.Action("ModifyData", "Home")'">修改资料</div>
            <div class="menu-item @(ViewBag.ActiveMenu == "ChangePassword" ? "active" : "")" onclick="location.href='@Url.Action("ChangePassword", "Home")'">修改密码</div>
            <div class="menu-item" onclick="location.href='@Url.Action("index", "Default")'">返回</div>
        </div>

        <div class="content">
            <div class="upload-section">
                <h2>上传头像</h2>
                <form id="avatarForm" enctype="multipart/form-data">
                    <input type="file" id="avatarInput" name="file" accept="image/*" style="display:none;" />
                    <div class="upload-btn" id="chooseBtn">选择图片</div>
                </form>
                <img id="avatarPreview" src="@ViewBag.ImageUrl" alt="" style="width:120px; height:120px; border-radius:50%; object-fit:cover; margin-top:20px;" />
            </div>
        </div>
    </div>

    <script>
    //基本信息跳转
        function Person() {

            window.location.href = 'Person';
        }
        //我的博客跳转
        function Blog() {
            window.location.href = 'Blog';
        }
        //修改资料跳转
        function ModifyData() {
            window.location.href = 'ModifyData';
        }
        //修改密码跳转
        function ChangePassword() {
            window.location.href = 'ChangePassword';
        }

        // 导航选项卡切换
        document.querySelectorAll('.nav-tab').forEach(tab => {
            tab.addEventListener('click', function() {
                document.querySelectorAll('.nav-tab').forEach(t => t.classList.remove('active'));
                this.classList.add('active');
            });
        });

        // 侧边栏菜单切换
        document.querySelectorAll('.menu-item').forEach(item => {
            item.addEventListener('click', function() {
                document.querySelectorAll('.menu-item').forEach(i => i.classList.remove('active'));
                this.classList.add('active');
            });
        });

        // 上传按钮交互
        document.getElementById('chooseBtn').onclick = function() {
            document.getElementById('avatarInput').click();
        };
        document.getElementById('avatarInput').onchange = function() {
            var formData = new FormData(document.getElementById('avatarForm'));
            fetch('/Home/Uploadface', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(res => {
                if(res.success) {
                    document.getElementById('avatarPreview').src = res.imageUrl;
                    alert('上传成功！');
                } else {
                    alert(res.message || '上传失败');
                }
            });
        };
    </script>
</body>
</html>

